package com.pwt.controller.basicsetting;

import com.pwt.annotation.Update;
import com.pwt.common.CustomException;
import com.pwt.entity.CpConfig;
import com.pwt.service.CpConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dw
 * @version 1.0.0
 * @date 2021/11/2
 */
@RestController
@Tag(name = "cp配置")
public class CpConfigController {

    CpConfigService cpConfigService;

    public CpConfigController(CpConfigService cpConfigService) {
        this.cpConfigService = cpConfigService;
    }

    @GetMapping("/cp-configs")
    @Operation(description = "cp目标配置列表",summary = "cp目标配置列表")
    public List<CpConfig> getList(){
        return this.cpConfigService.getList();
    };

    @PostMapping("/cp-config")
    @Operation(description = "新增",summary = "新增")
    public CpConfig add(@RequestBody @Validated CpConfig cp) throws CustomException {
        return this.cpConfigService.add(cp);
    };


    @PutMapping("/cp-config")
    @Operation(description = "修改",summary = "修改")
    public CpConfig update(@RequestBody @Validated(Update.class) CpConfig cp) throws CustomException {
        return this.cpConfigService.add(cp);
    };

    @PutMapping("/cp-config/{id}")
    @Operation(description = "修改",summary = "删除")
    public void update(@PathVariable String id) throws CustomException {
         this.cpConfigService.deleteCpConfig(id);
    };

}
